/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.common.web.form.student;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.util.LabelValueBean;

import ar.uba.fi.posgrado.common.model.Address;
import ar.uba.fi.posgrado.common.model.Degree;
import ar.uba.fi.posgrado.common.model.Student;

/**
 * Form para {@link Student Alumnos}
 * 
 * @author lautaro.gutierrez
 * @author pablo.tortorella
 * 
 */
@SuppressWarnings("serial")
public class StudentForm extends ActionForm {

	private Long id;

	private String name;

	private String surname;

	private String personalId;

	private String addressStreet;

	private String addressNumber;

	private String addressFloor;

	private String addressRoom;

	private String addressCity;

	private String addressTown;

	private String addressZipCode;

	private String nationality;

	private String phone;

	private String workPhone;

	private String mobile;

	private String email;

	private String email2;

	private Date registerDate;

	private String degreeName;

	private String university;

	private Integer degreeYear;

	private String company;

	private String position;

	private String selectedIdType;

	private List<LabelValueBean> idTypeOptions = new ArrayList<LabelValueBean>();

	private boolean createCustomer;

	private boolean complete;

	private List<Student> students;

	/**
	 * @return the email2
	 */
	public String getEmail2() {
		return email2;
	}

	/**
	 * @param email2
	 *            the email2 to set
	 */
	public void setEmail2(String email2) {
		this.email2 = email2;
	}

	/**
	 * @return the workPhone
	 */
	public String getWorkPhone() {
		return workPhone;
	}

	/**
	 * @param workPhone
	 *            the workPhone to set
	 */
	public void setWorkPhone(String workPhone) {
		this.workPhone = workPhone;
	}

	/**
	 * @return the idTypeOptions
	 */
	public List<LabelValueBean> getIdTypeOptions() {
		return idTypeOptions;
	}

	/**
	 * @param idTypeOptions
	 *            the idTypeOptions to set
	 */
	public void setIdTypeOptions(List<LabelValueBean> idTypeOptions) {
		this.idTypeOptions = idTypeOptions;
	}

	/**
	 * @return the selectedIdType
	 */
	public String getSelectedIdType() {
		return selectedIdType;
	}

	/**
	 * @param selectedIdType
	 *            the selectedIdType to set
	 */
	public void setSelectedIdType(String selectedIdType) {
		this.selectedIdType = selectedIdType;
	}

	/**
	 * @return the company
	 */
	public String getCompany() {
		return company;
	}

	/**
	 * @param company
	 *            the company to set
	 */
	public void setCompany(String company) {
		this.company = company;
	}

	/**
	 * @return the position
	 */
	public String getPosition() {
		return position;
	}

	/**
	 * @param position
	 *            the position to set
	 */
	public void setPosition(String position) {
		this.position = position;
	}

	/**
	 * @return the addressCity
	 */
	public String getAddressCity() {
		return addressCity;
	}

	/**
	 * @param addressCity
	 *            the addressCity to set
	 */
	public void setAddressCity(String addressCity) {
		this.addressCity = addressCity;
	}

	/**
	 * @return the addressFloor
	 */
	public String getAddressFloor() {
		return addressFloor;
	}

	/**
	 * @param addressFloor
	 *            the addressFloor to set
	 */
	public void setAddressFloor(String addressFloor) {
		this.addressFloor = addressFloor;
	}

	/**
	 * @return the addressRoom
	 */
	public String getAddressRoom() {
		return addressRoom;
	}

	/**
	 * @param addressRoom
	 *            the addressRoom to set
	 */
	public void setAddressRoom(String addressRoom) {
		this.addressRoom = addressRoom;
	}

	/**
	 * @return the addressTown
	 */
	public String getAddressTown() {
		return addressTown;
	}

	/**
	 * @param addressTown
	 *            the addressTown to set
	 */
	public void setAddressTown(String addressTown) {
		this.addressTown = addressTown;
	}

	/**
	 * @return the createCustomer
	 */
	public boolean isCreateCustomer() {
		return createCustomer;
	}

	/**
	 * @param createCustomer
	 *            the createCustomer to set
	 */
	public void setCreateCustomer(boolean createCustomer) {
		this.createCustomer = createCustomer;
	}

	/**
	 * @return the students
	 */
	public List<Student> getStudents() {
		return this.students;
	}

	/**
	 * @param students
	 *            the students to set
	 */
	public void setStudents(List<Student> students) {
		this.students = students;
	}

	/**
	 * @return the addressNumber
	 */
	public String getAddressNumber() {
		return addressNumber;
	}

	/**
	 * @param addressNumber
	 *            the addressNumber to set
	 */
	public void setAddressNumber(String addressNumber) {
		this.addressNumber = addressNumber;
	}

	/**
	 * @return the addressStreet
	 */
	public String getAddressStreet() {
		return addressStreet;
	}

	/**
	 * @param addressStreet
	 *            the addressStreet to set
	 */
	public void setAddressStreet(String addressStreet) {
		this.addressStreet = addressStreet;
	}

	/**
	 * @return the nationality
	 */
	public String getNationality() {
		return nationality;
	}

	/**
	 * @param nationality
	 *            the nationality to set
	 */
	public void setNationality(String nationality) {
		this.nationality = nationality;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the mobile
	 */
	public String getMobile() {
		return mobile;
	}

	/**
	 * @param mobile
	 *            the mobile to set
	 */
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the personalId
	 */
	public String getPersonalId() {
		return personalId;
	}

	/**
	 * @param personalId
	 *            the personalId to set
	 */
	public void setPersonalId(String personalId) {
		this.personalId = personalId;
	}

	/**
	 * @return the phone
	 */
	public String getPhone() {
		return phone;
	}

	/**
	 * @param phone
	 *            the phone to set
	 */
	public void setPhone(String phoneNumber) {
		this.phone = phoneNumber;
	}

	/**
	 * @return the surname
	 */
	public String getSurname() {
		return surname;
	}

	/**
	 * @param surname
	 *            the surname to set
	 */
	public void setSurname(String surname) {
		this.surname = surname;
	}

	/**
	 * @return the addressZipCode
	 */
	public String getAddressZipCode() {
		return addressZipCode;
	}

	/**
	 * @param addressZipCode
	 *            the addressZipCode to set
	 */
	public void setAddressZipCode(String zipCode) {
		this.addressZipCode = zipCode;
	}

	/**
	 * @return the registerDate
	 */
	public Date getRegisterDate() {
		return registerDate;
	}

	/**
	 * @param registerDate
	 *            the registerDate to set
	 */
	public void setRegisterDate(Date registerDate) {
		this.registerDate = registerDate;
	}

	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		createCustomer = false; // para que struts lo reconozca como checkbox
	}

	public Address getAddress() {
		Address address = new Address();
		address.setCity(this.getAddressCity());
		address.setFloor(this.getAddressFloor());
		address.setNumber(this.getAddressNumber());
		address.setRoom(this.getAddressRoom());
		address.setStreet(this.getAddressStreet());
		address.setTown(this.getAddressTown());
		address.setZipCode(this.getAddressZipCode());
		return address;
	}

	public void setAddress(Address address) {
		this.setAddressCity(address.getCity());
		this.setAddressFloor(address.getFloor());
		this.setAddressNumber(address.getNumber());
		this.setAddressRoom(address.getRoom());
		this.setAddressStreet(address.getStreet());
		this.setAddressTown(address.getTown());
		this.setAddressZipCode(address.getZipCode());
	}

	public Degree getDegree() {
		Degree degree = new Degree();
		degree.setDegree(this.getDegreeName());
		degree.setUniversity(this.getUniversity());
		degree.setYear(this.getDegreeYear());
		return degree;
	}

	public void setDegree(Degree degree) {
		this.setDegreeName(degree.getDegree());
		this.setUniversity(degree.getUniversity());
		this.setDegreeYear(degree.getYear() == 0 ? null : degree.getYear());
	}

	/**
	 * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
	 *      javax.servlet.http.HttpServletRequest)
	 */
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors actionErrors = new ActionErrors();

		if (this.name.trim().equals("")) {
			actionErrors.add("student.name", new ActionMessage(
					"student.name.empty"));
		}
		if (this.surname.trim().equals("")) {

			actionErrors.add("student.surname", new ActionMessage(
					"student.surname.empty"));
		}
		if (this.addressCity.trim().equals("")
				|| this.addressTown.trim().equals("")
				|| this.addressStreet.trim().equals("")
				|| this.addressNumber.trim().equals("")) {
			actionErrors.add("customer.address", new ActionMessage(
					"student.address.empty"));
		}

		return actionErrors;
	}

	/**
	 * @return the degreeName
	 */
	public String getDegreeName() {
		return degreeName;
	}

	/**
	 * @param degreeName
	 *            the degreeName to set
	 */
	public void setDegreeName(String degree) {
		this.degreeName = degree;
	}

	/**
	 * @return the degreeYear
	 */
	public Integer getDegreeYear() {
		return degreeYear;
	}

	/**
	 * @param degreeYear
	 *            the degreeYear to set
	 */
	public void setDegreeYear(Integer degreeYear) {
		this.degreeYear = degreeYear;
	}

	/**
	 * @return the university
	 */
	public String getUniversity() {
		return university;
	}

	/**
	 * @param university
	 *            the university to set
	 */
	public void setUniversity(String university) {
		this.university = university;
	}

	public boolean getComplete() {
		return complete;
	}

	public void setComplete(boolean complete) {
		this.complete = complete;
	}

}
